package yxy.game.pm2.command.tower;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.TowerMessage;
import yxy.game.pm2.module.tower.TowerModule;

/** 修炼塔 目标界面 */
@MessageType(proto = Command.TowerTask, classtype = TowerMessage.TowerTaskRequest.class)
public class CMD_TowerTask extends Command<TowerMessage.TowerTaskRequest> {

	@Override
	public void execute(MessageSource messageSource, TowerMessage.TowerTaskRequest request) {
		String playerCode = messageSource.getTag();

		TowerMessage.TowerTaskResponse.Builder response = TowerMessage.TowerTaskResponse.newBuilder();

		TowerModule towerModule = TowerModule.get(playerCode);
		for (Integer levelRewardId : towerModule.getLevelReward()) {
			response.addBox(levelRewardId);
		}

		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, TowerMessage.TowerTaskResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}